/*
 * Created by IntelliJ IDEA.
 * User: amrk
 * Date: 15/02/2005
 * Time: 19:27:14
 */
package com.talios.jira.browser;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class ColumnMetaInfo {
    private String id;
    private String[] fieldNames;
    private String displayFieldName;
    private int position;

    public String getId() {
        return id;
    }

    public String[] getFieldNames() {
        return fieldNames;
    }

    public String getDisplayFieldName() {
        return displayFieldName;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public ColumnMetaInfo(String id, String[] fieldNames, String displayFieldName, int position) {
        this.id = id;
        this.fieldNames = fieldNames;
        this.displayFieldName = displayFieldName;
        this.position = position;
    }

    public static Map<String, ColumnMetaInfo> getColumnDefinitions() {

        // TODO Return this to a List
        Map<String, ColumnMetaInfo> map = new TreeMap<String, ColumnMetaInfo>();

        map.put("created", new ColumnMetaInfo("Created", new String[]{"created"}, "created", 0));
        map.put("key", new ColumnMetaInfo("Key", new String[]{"keyName", "keyValue"}, "key", 1));
        map.put("component", new ColumnMetaInfo("Component", new String[]{"component"}, "component", 2));
        map.put("title", new ColumnMetaInfo("Title", new String[]{"title"}, "title", 3));
        map.put("type", new ColumnMetaInfo("Type", new String[]{"type"}, "type", 4));
        map.put("priority", new ColumnMetaInfo("Priority", new String[]{"priority"}, "priority", 5));
        map.put("status", new ColumnMetaInfo("Status", new String[]{"status"}, "status", 6));
        map.put("resolution", new ColumnMetaInfo("Resolution", new String[]{"resolution"}, "resolution", 7));
        map.put("assignee", new ColumnMetaInfo("Assignee", new String[]{"assignee"}, "assignee", 8));
        map.put("reporter", new ColumnMetaInfo("Reporter", new String[]{"reporter"}, "reporter", 9));
        map.put("updated", new ColumnMetaInfo("Updated", new String[]{"updated"}, "updated", 10));
        map.put("dueDate", new ColumnMetaInfo("Due Date", new String[]{"dueDate"}, "dueDate", 11));
        map.put("version", new ColumnMetaInfo("Version", new String[]{"version"}, "version", 12));
        map.put("fixVersion", new ColumnMetaInfo("Fix Version", new String[]{"fixVersion"}, "fixVersion", 13));
        return map;
    }

    public static String[] getColumnKeys() {
        return getColumnDefinitions().keySet().toArray(new String[]{});
    }

    public static List<? extends ColumnSetting> getDefaultColumnSettings() {
        List columnList = new ArrayList();

        Map<String, ColumnMetaInfo> map = getColumnDefinitions();
        for (String columnKey : map.keySet()) {
            ColumnMetaInfo columnMetaInfo = map.get(columnKey);
            columnList.add(new ColumnSetting(
                    columnKey,
                    columnMetaInfo.getPosition(),
                    -1));
        }

        return columnList;
    }

}
